//go:generate sqlboiler mysql
package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
	"github.com/volatiletech/sqlboiler/boil"
	"github.com/volatiletech/sqlboiler/queries/qm"

	"db/test2/models"
)

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

const (
	dataSourceName = `lwj:Ryt5mOTt@tcp(192.168.1.61:3306)/test?charset=utf8`
)

func main() {
	boil.DebugMode = true

	db, err := sql.Open("mysql", dataSourceName)
	checkErr(err)

	p := &models.Pilot{
		Name: "jack",
	}
	fmt.Printf("%+v\n", p)
	err = p.Insert(db)
	checkErr(err)

	fmt.Printf("%+v\n", p)

	pilots, err := models.Pilots(db, qm.Where("id=?", p.ID)).All()
	checkErr(err)

	for _, p := range pilots {
		log.Printf("%#v\n", p)
	}

	//err = models.Pilots(db).DeleteAll()
	//checkErr(err)
}
